package com.example.guideapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.guideapp.R;
import com.example.guideapp.bean.MyFestival;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Administrator on 2017/10/28.
 */

public class MyDayListViewAdapter extends BaseAdapter implements Serializable{

    private List<MyFestival> list;
    private Context context;
    private LayoutInflater inflater;
    private MyFestival myFestival;

    public MyDayListViewAdapter(List<MyFestival> list, Context context) {
        this.list = list;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (list != null){
            return list.size();
        }else {
            return 0;
        }
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder viewHolder;

        if (view == null){
            view  = inflater.inflate(R.layout.fragment3_listview_item,null);
            viewHolder = new ViewHolder();

            viewHolder.myDay_name = (TextView) view.findViewById(R.id.tv3_name);
            viewHolder.myDay_date = (TextView) view.findViewById(R.id.tv3_date);

            view.setTag(viewHolder);
        }else{

            viewHolder = (ViewHolder) view.getTag();
        }

        myFestival = list.get(i);

        viewHolder.myDay_name.setText(myFestival.getName());
        viewHolder.myDay_date.setText(myFestival.getDate());

        return view;
    }

    static class ViewHolder{
        private TextView myDay_name;
        private TextView myDay_date;
    }

    public void refresh(List<MyFestival> list) {
        this.list = list;
        notifyDataSetChanged();
    }

}
